<?php
if (!class_exists('RoleDao')) {
	/**
	 *  Propel DAO class for user roles operations
	 *	@author Alecsandru Gabriel DINU
	 *  @since Jun 27, 2008
	 * 
	 *  @Bean(id = "roleDao")
	 */
	class RoleDao extends BaseDao {
		
		/**
		 * Saves a role in the database with Propel.
		 * @access public
		 * @param Role
		 * @return integer Number of affected rows
		 * @throws  ResourceAlreadyExistsException
		 */
		public function save($role) {
			try {
				return $role->save();
			} catch (PropelException $e) {
				throw new ResourceAlreadyExistsException($e);	
			}			
			
		}
		
		/**
		 * Gets a role from the database based on its id
		 * @access public
		 * @param integer
		 * @return Role
		 */		
		public function getById($id) {
			return RolePeer::retrieveByPK($id);
		}

		/**
		 * Gets all the roles from the database
		 * @access public
		 * @return array
		 */
		public function getAll() {
			return RolePeer::doSelect(new Criteria());
		}
		
		/**
		 * Gets a role from the database based on its name
		 * @access public
		 * @param string
		 * @return Role
		 */
		public function getByName($name) {
			$c = new Criteria();
			$c->add(RolePeer::NAME, $name);
			return RolePeer::doSelectOne($c);
		}
		
	}
}
?>